#!/bin/sh
##
## compil.sh
## Login : <ctaf@CTAF-FIX.CTAFLAND>
## Started on  Sat Dec 22 04:01:38 2007 GESTES Cedric
## $Id$
##
## Copyright (C) 2007 GESTES Cedric
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##

PLUGINS="cairo-dock clock dustbin logout rhythmbox rendering systray terminal shortcuts gnome-integration Xgamma"

#launch a command into a folder
#arg1 is the module name
#arg2 the command to launch
#arg3 the argument to the command
cmd_module() {
  local mod="$1"
  local cmd="$2"
  local arg="$3"
  local log=`pwd`/$mod.log
  local prevpwd=`pwd`

  #open the folder
  if [ "x$mod" = "xcairo-dock" ]; then
    cd "$mod"
  else
    cd "plug-ins/$mod"
  fi

  #launch the command
  eval $cmd &> $log

  #remove the log on success, or display it then exit with error
  if [ $? -eq 0 ]; then
    rm $log
  else
    echo "ERROR: COMPILATION FAILED"
    cat $log
    exit 1
  fi

  #reopen the previous folder
  cd $prevpwd
}


svn_update()
{
  #if the folder doesnt exist checkout otherwize update
  if [ -d /opt/cairo-dock/cairo-dock-svn ]; then
    svn co http://svn.berlios.de/svnroot/repos/cairo-dock/trunk cairo-dock-svn
  else
    cd /opt/cairo-dock/
    svn up
  fi
}

#MAIN
act=$1
mod=$2

if [ "x$act" = "x-s" ] ; then
  svn_update;

elif [ "x$act" = "x-m" ] ; then
  cmd_module "$mod" "autoreconf -isvf" "";
  cmd_module "$mod" "./configure" "--prefix=/usr $arg";
  cmd_module "$mod" "make"
  cmd_module "$mod" "sudo make install"

elif [ "x$act" = "x-mg" ] ; then
  cmd_module "$mod" "autoreconf -isvf" "";
  cmd_module "$mod" "./configure" "--prefix=/usr --enable-glitz";
  cmd_module "$mod" "make"
  cmd_module "$mod" "sudo make install"

elif [ "x$act" = "x-u" ] ; then
  cmd_module "$mod" "autoreconf -isvf" "";
  cmd_module "$mod" "./configure" "--prefix=/usr --enable-glitz";
  cmd_module "$mod" "make"
  cmd_module "$mod" "sudo make uninstall"

else
  echo "-m MODULE: install module"
  echo "-s: svn update"
  echo "-u MODULE: uninstall"
  echo "-mg MODULE: install with glitz"
  echo "return 0 on success, 1 on error"
fi
